package com.fitsoftwareprocess.mobilemap;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

public class ResultStartPointActivity extends TabActivity implements TabHost.TabContentFactory {

	String startKeyWord;
	Intent intent; 
	RadioButton rbFirst;   
    RadioButton rbSecond ; 
    int tab = 0;
    RadioButton[] rdTabs = new RadioButton[2];
	private String endKeyWord;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resultstartpoint);
        startKeyWord = getIntent().getExtras().getString("startkeyword");
        endKeyWord = getIntent().getExtras().getString("endkeyword");
        tab=getIntent().getExtras().getInt("tab");
        TabHost tabHost = getTabHost();
        intent = new Intent().setClass(this, ListAddressActivity.class);
        intent.putExtra("keyword", startKeyWord);
        intent.putExtra("from", "ResultStartPointActivity");
        intent.putExtra("endkeyword", endKeyWord);
        
        tabHost.addTab(tabHost.newTabSpec("listAddress").setIndicator("ListAddress").setContent(intent));
        intent = new Intent().setClass(this, ListServiceActivity.class);
        intent.putExtra("keyword", startKeyWord);
        intent.putExtra("from", "ResultStartPointActivity");
        intent.putExtra("endkeyword", endKeyWord);
        tabHost.addTab(tabHost.newTabSpec("listService").setIndicator("ListService").setContent(intent));
        setupUI();
        setTab(tab);
    }
    public View createTabContent(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	private void setTab(int index)
	{
		getTabHost().setCurrentTab(index);
		switch (index) {
		case 0:
			rdTabs[0].setButtonDrawable(R.drawable.diachi1);
			rdTabs[1].setButtonDrawable(R.drawable.dichvu2);
			
			break;
		case 1:
			rdTabs[0].setButtonDrawable(R.drawable.diachi2);
			rdTabs[1].setButtonDrawable(R.drawable.dichvu1);
			
			break;

		default:
			break;
		}
		for(int i = 0;i<rdTabs.length;i++)
		{
			if(i == index)
			{
				rdTabs[i].setBackgroundColor(Color.TRANSPARENT);
				
			}
			else
			{
				rdTabs[i].setBackgroundColor(Color.TRANSPARENT);
			}
		}
	}
	private void setupUI() {
	
		rdTabs[0] = (RadioButton) findViewById(R.id.first_mainresult);
         
		rdTabs[1] = (RadioButton) findViewById(R.id.second_mainresult); 
  
		rdTabs[0].setButtonDrawable(R.drawable.home);
		rdTabs[1].setButtonDrawable(R.drawable.address);  
		
	
        
		for(int i = 0;i<rdTabs.length;i++)
		{
			if(i == 0)
			{
				rdTabs[i].setBackgroundColor(Color.LTGRAY);
			}
			else
			{
				rdTabs[i].setBackgroundColor(Color.DKGRAY);
			}
		}
         
        RadioGroup rg = (RadioGroup) findViewById(R.id.states_mainresult);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, final int checkedId) {

                switch (checkedId) {
                
                case R.id.first_mainresult:
                {
                    setTab(0);
                    break;
                }
                case R.id.second_mainresult:
                {

                    setTab(1);
                    break;
                }
            
         
                
                }
            }
        });
	}


}
